package cc.vv.btpartyjob.partymanager.delegate

import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.TextView
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.adapter.QiShiYeDanWeiListAdapter
import cc.vv.mvp.delegate.BaseAppDelegate
import cc.vv.party.beans.vo.OrgVO
import com.chad.library.adapter.base.BaseQuickAdapter

/**
 * 企事业单位列表
 * Created by Chen.qi on 2018/10/24.
 */
class QiShiYeDanWeiActivityDelegate : BaseAppDelegate() {

    /**
     * 网格适配器
     */
    private var mAdapter: QiShiYeDanWeiListAdapter? = null

    override fun initWidget() {
        mAdapter = QiShiYeDanWeiListAdapter(R.layout.item_wangge_list)
        val recyclerView = getView<RecyclerView>(R.id.rv_awl_listData)
        recyclerView?.layoutManager = GridLayoutManager(getActivity(), 4)
        recyclerView?.adapter = mAdapter
    }

    override fun initLayoutRes(): Int {
        return R.layout.activity_wangge_list
    }

    /**设置标题title*/
    fun setTopBarTitle(topBarTitle: String, boolean: Boolean = false) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_awl_topBar)
        titleBar?.setTitle(topBarTitle)
        if (boolean) {
            titleBar?.rl_ljtb_right_layout?.visibility = View.VISIBLE
        } else {
            titleBar?.rl_ljtb_right_layout?.visibility = View.GONE
        }
    }


    /**设置标题右边按钮点击事件*/
    fun setTitleBackBtnOnClick(event: BaseTopBarView.EventInterface) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_awl_topBar)
        titleBar?.setEventInterface(event)
    }


    /** 数据适配器 */
    fun setAdapterData(list: List<OrgVO>?) {
        if (null != list) {
            mAdapter?.setNewData(list)
            if (list.isEmpty()) {
                showNoDataView(true)
            } else {
                showNoDataView(false)
            }
        } else {
            showNoDataView(true)
        }
    }


    /** 显示暂无数据缺省页 */
    private fun showNoDataView(isNoData: Boolean) {
        val noData = getView<TextView>(R.id.tv_awl_noData)
        if (isNoData) {
            noData?.visibility = View.VISIBLE
        } else {
            noData?.visibility = View.GONE
        }
    }


    /** 设置列表 Item 点击事件*/
    fun bindOnItemClick(onItemClickListener: BaseQuickAdapter.OnItemClickListener) {
        mAdapter?.onItemClickListener = onItemClickListener
    }


}